package jiaerc.moreingredients.handler;

import jiaerc.moreingredients.MoreIngredientsEffects;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.PotionItem;
import net.minecraft.potion.PotionUtils;
import net.minecraft.potion.Potions;
import net.minecraftforge.event.entity.living.LivingEntityUseItemEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
//导入自己的类
import jiaerc.moreingredients.effect.EffectSpicy;

//通过喝水去除辛辣效果
public class DrinkWaterHandler {
    @SubscribeEvent
    public void onDrink(LivingEntityUseItemEvent.Finish event) {//事件触发时机：当实体完成物品使用的时候
        if (event.getItem().getItem() instanceof PotionItem
                && PotionUtils.getPotion(event.getItem()) == Potions.WATER) {//检测药水物品堆栈中的药水类型是否为水
            LivingEntity entity = event.getEntityLiving();
            if (entity.hasEffect(MoreIngredientsEffects.SPICY_EFFECT.get())) {//如果是辛辣效果
                EffectSpicy.markAsDrankWater(entity);
                entity.removeEffect(MoreIngredientsEffects.SPICY_EFFECT.get());
            }
        }
    }
}